//
//  MediaView.m
//  SecondPage
//
//  Created by xiong qi on 13-4-18.
//  Copyright (c) 2013年 winston. All rights reserved.
//

#import "MediaView.h"
#import "../../Common/Common/MoviePlayView.h"
#import "../../Common/Common/ZoomImageView.h"

@implementation MediaView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width,frame.size.height )];
        [self addSubview:contentView];
        [contentView release];
        [contentView setBackgroundColor:[UIColor blackColor]];
        
        closebtn = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width-60, 5, 54, 54)];
        [self addSubview:closebtn];
        [closebtn release];
        [closebtn setImage:[UIImage imageNamed:@"AllAuto_Button_FullScreen_Close"] forState:UIControlStateNormal];
        [closebtn addTarget:self action:@selector(onClick) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return self;
}

-(void)Refresh:(NSString *)path Type:(int)type
{
    for (UIView * item in contentView.subviews) {
        [item removeFromSuperview];
    }
    
    if (type == 0) {
        ZoomImageView *zoomImageView = [[ZoomImageView alloc] initWithFrame:contentView.bounds];
        [contentView addSubview:zoomImageView];
        [zoomImageView release];
        
        UITapGestureRecognizer *tapGes=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapZoomImageView:)];
        [zoomImageView addGestureRecognizer:tapGes];
        [tapGes release];
        
        UIImage * tempimg = [[UIImage alloc]initWithContentsOfFile:path];
        
        if (tempimg) {
            [zoomImageView.imgView setImage:tempimg];
            [tempimg release];
        }
        
    }
    else if(type == 1)
    {
        MoviePlayView * playview = [[MoviePlayView alloc] initWithFrame:CGRectMake(0, 0, contentView.frame.size.width, contentView.frame.size.height)];
        [contentView addSubview:playview];
        [playview release];
        [playview SetPlayPath:path];
    }
}

-(void)onClick
{
    [UIView animateWithDuration:0.5
                     animations:^{
                         
                         self.alpha = 0;
                         
                     }
                     completion:^(BOOL finished){
                         
                         for (UIView * item in contentView.subviews) {
                             [item removeFromSuperview];
                         }
                         [self removeFromSuperview];
                     }];

}

-(void) onTapZoomImageView:(UITapGestureRecognizer *)tapGesture{
    [self onClick];
}



@end
